<template>
  <!-- 大客户部总监审核 -->
  <div>
    <!-- 搜索 -->
    <commonFilter @filterChange="changeHandle" @onCollapse="collapseHandle" />
    <!-- table -->
    <FilterTable
      ref="table"
      :columns="columns"
      :fetchapi="fetchParams"
      :isSelectColumn="isSelectColumn"
      :params="flterValue"
      :datakey="'records'"
      :onColumnsChange="columns => this.columns = columns"
    ></FilterTable>
    <Drawer
      ref="infoDrawer"
      :visible.sync="visibleDrawer"
      title="审批明细"
      :width="920"
      destroyOnClose
      :containerStyle="{height: 'calc(100% - 60px)', overflow: 'auto', paddingBottom: '60px'}"
    >
      <info-modal v-model="infoId" :infoType="type" @close="infoClose" />
    </Drawer>
  </div>
</template>
<script>
import infoModal from '../approvalDetails/index';
import commonFilter from '../commonFilter/index';
import { dictionary } from '@/utils/dictMixin';
export default {
  mixins: [dictionary],
  components: {
    infoModal,
    commonFilter
  },
  data() {
    return {
      visibleDrawer: false,
      isSelectColumn: false,
      infoId: '', //记录行id
      type: 'add', //add编辑 ，info详情
      flterValue: {}, //参数
      columns: this.creatHeader(),
      fetchParams: null //ipa 接口
    };
  },
  mounted() {
    this.BaseTable = this.$refs.table.$refs.pageTable;
  },
  methods: {
    //搜索获取数据
    changeHandle(val) {
      this.flterValue = val;
      console.log(val);
    },
    //table表头和数据源
    creatHeader() {
      return [
        {
          title: '序号',
          dataIndex: 'index',
          width: 80,
          sorter: true,
          render: props => {
            return <span>{props.row.index + 1}</span>;
          }
        },
        {
          title: '操作',
          dataIndex: 'column-action',
          width: 100,
          fixed: 'left',
          render: (props, h) => {
            return (
              <div>
                <el-button size="mini" type="text" onClick={() => this.editHandle(props.row)}>
                  编辑
                </el-button>
                <el-divider direction="vertical" />
                <el-button size="mini" type="text" onClick={() => this.detailHandle(props.row)}>
                  明细
                </el-button>
              </div>
            );
          }
        },
        { title: '项目状态', dataIndex: 'field0', sorter: true },
        { title: '项目名称', dataIndex: 'field1', sorter: true },
        { title: '客户公司名称', dataIndex: 'field2', sorter: true },
        {
          title: '客户类型',
          dataIndex: 'field01',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }
        },
        { title: '客户性质', dataIndex: 'field02', sorter: true },
        { title: '事业部', dataIndex: 'field13', sorter: true },
        { title: '经销商', dataIndex: 'field03', sorter: true },
        { title: '所在省', dataIndex: 'field3', sorter: true },
        { title: '所在市', dataIndex: 'field4', sorter: true },
        { title: '所在县/区', dataIndex: 'field5', sorter: true },
        { title: '详细地址', dataIndex: 'field6', sorter: true },
        {
          title: '客户状态',
          dataIndex: 'field9',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }
        },
        { title: '客户来源', dataIndex: 'field91', sorter: true },
        { title: '所属行业分类', dataIndex: 'field10', sorter: true },
        { title: '行业地位', dataIndex: 'field11', sorter: true },
        { title: '购车用途', dataIndex: 'field12', sorter: true },
        { title: '预计采购日期', dataIndex: 'field13', sorter: true },
        {
          title: '客户采购方式',
          dataIndex: 'field14',
          sorter: true,
          render: props => {
            //编码转汉字
            return <span>{this.createDictText(props.row.basedataRelateId, '1611')}</span>;
          }
        }
      ];
    },
    //编辑
    editHandle(infoRow) {
      //逻辑自己写
      this.visibleDrawer = true;
      this.infoId = 1000;
      this.type = 'add';
    },
    //详情
    detailHandle(row) {
      //逻辑自己写
      this.visibleDrawer = true;
      this.infoId = 1000;
      this.type = 'info';
    },
    //关闭详情
    infoClose() {
      this.visibleDrawer = false;
      if (type === 'refresh') {
        // 重新加载
        this.fetchParams = { ...this.fetchParams };
      }
    },
    collapseHandle() {
      this.$nextTick(() => {
        this.BaseTable.EXECUTE_RESET_HEIGHT();
      });
    }
  }
};
</script>

<style lang="less" scoped>
</style>
